home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / include / oldproc.h < prev    next >
C/C++ Source or Header  |  1989-08-08  |  18KB  |  572 lines

  1. /*
  2.  * procUser.h --
  3.  *
  4.  *    Definitions for use in the Proc system calls.
  5.  *
  6.  * Copyright 1986, 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  *
  15.  * $Header: /sprite/src/lib/include/RCS/proc.h,v 1.9 89/08/08 11:09:30 douglis Exp $ SPRITE (Berkeley)
  16.  */
  17.  
  18. #ifndef _PROCUSER
  19. #define _PROCUSER
  20.  
  21. #include <spriteTime.h>
  22. #include <sig.h>
  23. #include <kernel/mach.h>
  24. #ifdef KERNEL
  25. #include <user/vm.h>
  26. #else
  27. #include <vm.h>
  28. #endif
  29.  
  30. /*
  31.  * Process Termination Reason flags:
  32.  *
  33.  *   PROC_TERM_EXITED        - The process has called Proc_Exit.
  34.  *   PROC_TERM_DETACHED        - The process has called Proc_Detach.
  35.  *   PROC_TERM_SIGNALED        - The process has died because of a signal.
  36.  *   PROC_TERM_DESTROYED    - The process has died because the internal
  37.  *                  state of the process was found to be
  38.  *                  invalid as a result of a user level error.
  39.  *   PROC_TERM_SUSPENDED    - The process has been suspended.
  40.  *   PROC_TERM_RESUMED        - The process has resumed execution as the
  41.  *                  result of a resume signal.
  42.  */
  43.  
  44. #define PROC_TERM_EXITED        1
  45. #define PROC_TERM_DETACHED        2
  46. #define PROC_TERM_SIGNALED        3
  47. #define PROC_TERM_DESTROYED        4
  48. #define    PROC_TERM_SUSPENDED        5
  49. #define    PROC_TERM_RESUMED        6
  50.  
  51. /*
  52.  * Reasons why a process was destroyed (PROC_TERM_DESTROYED):
  53.  * 
  54.  * PROC_BAD_STACK        - A process's user stack is invalid upon
  55.  *                  return from a signal handler.
  56.  * PROC_BAD_PSW         - The processor status word that is to be
  57.  *                  restored upon return from a signal handler
  58.  *                  has the supervisor bit set.
  59.  * PROC_VM_READ_ERROR        - The virtual memory system couldn't read from
  60.  *                  the page server.
  61.  * PROC_VM_WRITE_ERROR        - The virtual memory system couldn't write to
  62.  *                  the page server.
  63.  */
  64.  
  65. #define    PROC_BAD_STACK            1
  66. #define    PROC_BAD_PSW            2
  67. #define    PROC_VM_READ_ERROR        3
  68. #define    PROC_VM_WRITE_ERROR        4
  69.  
  70. /*
  71.  *  Definition of a process ID.
  72.  */
  73.  
  74. typedef unsigned int     Proc_PID;
  75.  
  76.  
  77. /*
  78.  * Special values to indicate the pid of the current process, or the host on
  79.  * which it is running, respectively.
  80.  */
  81.  
  82. #define PROC_MY_PID    ((Proc_PID) 0xffffffff)
  83. #define PROC_MY_HOSTID    ((unsigned int) 0xffffffff)
  84.  
  85. /*
  86.  * Mask to extract process table index from pid.
  87.  */
  88. #define    PROC_INDEX_MASK        0x000000FF
  89.  
  90. /*
  91.  * Convert a process id into a process table index.
  92.  */
  93. #define    Proc_PIDToIndex(pid) (pid & PROC_INDEX_MASK)
  94.  
  95. /*
  96.  * Special parameter to Proc_Migrate to evict all processes from a
  97.  * workstation.
  98.  */
  99.  
  100. #define PROC_ALL_PROCESSES    ((Proc_PID) 0)
  101.  
  102. /*
  103.  * Special family value to indicate the process isn't in a family and 
  104.  * a macro to see if the process is in a family.
  105.  */
  106.  
  107. #define PROC_NO_FAMILY    (Proc_PID) -1
  108. #define Proc_In_A_Family(familyID) (familyID != PROC_NO_FAMILY)
  109.  
  110.  
  111. /*
  112.  * PROC_SUPER_USER_ID is the user ID of the omnipotent super-user and 
  113.  * PROC_NO_ID is used when specifying no id to the Proc_SetIDs call.
  114.  */
  115.  
  116. #define PROC_SUPER_USER_ID      0
  117. #define PROC_NO_ID          -1
  118.  
  119. /*
  120.  * PROC_NO_INTR_PRIORITY is used to provide system processes 
  121.  *  infinitely-high priority.
  122.  */
  123.  
  124. #define PROC_MIN_PRIORITY    -2
  125. #define PROC_MAX_PRIORITY     2
  126.  
  127. #define PROC_NO_INTR_PRIORITY     2
  128. #define PROC_HIGH_PRIORITY     1
  129. #define PROC_NORMAL_PRIORITY     0
  130. #define PROC_LOW_PRIORITY    -1
  131. #define PROC_VERY_LOW_PRIORITY    -2
  132.  
  133. /*
  134.  *  Process state flags:
  135.  */
  136. typedef enum {
  137.     PROC_UNUSED,    /* The process doesn't exist yet. */
  138.     PROC_RUNNING,    /* The process is executing on a processor. */
  139.     PROC_READY,        /* The process is ready to execute. */
  140.     PROC_WAITING,    /* The process is waiting for an event to occur such
  141.              * as I/O completion or a mutex lock released. */
  142.     PROC_EXITING,    /* The process has terminated and is on the 
  143.              * exiting list. */
  144.     PROC_DEAD,        /* The process has been terminated is on the dead list*/
  145.     PROC_MIGRATED,    /* The process is running on a remote machine. */
  146.     PROC_NEW,        /* The process was just created. */
  147.     PROC_SUSPENDED    /* The process is suspended. */
  148. } Proc_State;
  149.  
  150. /*
  151.  * Process attributes flags:
  152.  *
  153.  *  PROC_KERNEL               - The process is a kernel process.
  154.  *  PROC_USER                 - The process is a user process.
  155.  *  PROC_DEBUGGED        - The process is being debugged by the system
  156.  *                  debugger.
  157.  *  PROC_DEBUG_ON_EXEC        - The process will start in debugged mode.
  158.  *  PROC_DEBUG_WAIT        - A debugger is waiting for this process to go
  159.  *                  onto the debug list.
  160.  *  PROC_SINGLE_STEP_FLAG    - The process will have the trace bit set
  161.  *                  before it runs.
  162.  *  PROC_MIG_PENDING        - The process will be migrated when it
  163.  *                  completes its next trap.
  164.  *  PROC_DONT_MIGRATE        - The process should not be migrated yet, even
  165.  *                  when it traps.
  166.  *  PROC_FOREIGN        - The process has been migrated from another
  167.  *                  workstation to this one.
  168.  *  PROC_DIEING            - The process is comitting hari-kari.
  169.  *  PROC_LOCKED            - This process is locked.
  170.  *  PROC_NO_VM            - The virtual memory resources have been
  171.  *                  freed up for this user process.
  172.  *  PROC_MIGRATING        - The process is in the middle of migrating
  173.  *                  to another workstation.  This happens after
  174.  *                  PROC_MIG_PENDING is set but before the
  175.  *                  process's state becomes PROC_MIGRATED and
  176.  *                  its PROC_MIGRATION_DONE flag is set.
  177.  *  PROC_MIGRATION_DONE        - indicates successful completion of a
  178.  *                  migration trap.
  179.  *  PROC_ON_DEBUG_LIST        - the process is on the debug list.
  180.  *  PROC_REMOTE_EXEC_PENDING    - The process should perform an exec as part
  181.  *                  of migration.
  182.  *  PROC_MIG_ERROR        - indicates asynchronous error before
  183.  *                  migrating process context switches.
  184.  */
  185.  
  186. #define PROC_KERNEL            0x00001
  187. #define PROC_USER            0x00002
  188. #define PROC_DEBUGGED            0x00004
  189. #define PROC_DEBUG_ON_EXEC        0x00008
  190. #define PROC_SINGLE_STEP_FLAG        0x00010
  191. #define PROC_DEBUG_WAIT            0x00020
  192. #define PROC_MIG_PENDING        0x00040
  193. #define PROC_DONT_MIGRATE        0x00080
  194. #define PROC_FOREIGN            0x00100
  195. #define PROC_DIEING            0x00200
  196. #define PROC_LOCKED            0x00400
  197. #define PROC_NO_VM            0x00800
  198. #define PROC_MIGRATING            0x01000
  199. #define PROC_MIGRATION_DONE        0x02000
  200. #define PROC_ON_DEBUG_LIST        0x04000
  201. #define PROC_REMOTE_EXEC_PENDING    0x08000
  202. #define PROC_MIG_ERROR            0x10000
  203.  
  204.  
  205.  
  206. /*
  207.  *  Resource usage summary for a process. 
  208.  *  Used by Proc_Wait and Proc_GetResUsage.
  209.  *
  210.  *   Preliminary version: more fields will be added when needed.
  211.  *
  212.  *  Note: the cpu usage fields use the Time format. In the process
  213.  *  control block, they are stored in the Timer_Ticks format.
  214.  *  They are converted to Time format by the system calls that return
  215.  *  resource usage info.
  216.  */
  217.  
  218. typedef struct {
  219.     Time kernelCpuUsage;    /* How much time has been spent in kernel mode*/
  220.     Time userCpuUsage;        /* How much time has been spent in user mode. */
  221.  
  222.     Time childKernelCpuUsage;    /* Sum of time spent in kernel mode for 
  223.                  * all terminated children. */
  224.     Time childUserCpuUsage;    /* Sum of time been spent in user mode for
  225.                  * all terminated children. */
  226.     int    numQuantumEnds;        /* number of times the process was
  227.                  * context switched due to a quantum end. */
  228.     int numWaitEvents;        /* number of times the process was
  229.                       * context switched due to its waiting for
  230.                  *  an event. */
  231. } Proc_ResUsage;
  232.  
  233. /*
  234.  *  Request values for use with Proc_Debug system call.
  235.  */
  236.  
  237. typedef enum {
  238.     PROC_GET_THIS_DEBUG,
  239.     PROC_GET_NEXT_DEBUG,
  240.     PROC_CONTINUE,
  241.     PROC_SINGLE_STEP,
  242.     PROC_GET_DBG_STATE,
  243.     PROC_SET_DBG_STATE,
  244.     PROC_READ,
  245.     PROC_WRITE,
  246.     PROC_DETACH_DEBUGGER
  247. } Proc_DebugReq;
  248.  
  249. /*
  250.  * Flags to Proc_Wait
  251.  *
  252.  *         PROC_WAIT_BLOCK    -    Block if there if are no stopped or
  253.  *                terminated processes.
  254.  *    PROC_WAIT_FOR_SUSPEND - Return status of children that are suspended.
  255.  *                If this option isn't specified and children
  256.  *                are stopped then it is as though they are
  257.  *                still running.
  258.  */
  259. #define    PROC_WAIT_BLOCK        0x1
  260. #define    PROC_WAIT_FOR_SUSPEND    0x2
  261.  
  262. #define PROC_NUM_GENERAL_REGS 16
  263.  
  264. typedef struct {
  265.     Proc_PID    processID;        /* Process ID of debuggee */
  266.     int    termReason;            /* Reason why process has died or
  267.                      * it has been detached. */
  268.     int    termStatus;            /* Exit/detach status or signal number
  269.                      * that caused the process to die. */
  270.     int    termCode;            /* The code for the signal. */
  271.     Mach_RegState regState;        /* The register state of the process. */
  272.     int    sigHoldMask;            /* Mask of signals to be held. */
  273.     int    sigPendingMask;            /* Mask of pending signals. */
  274.     int    sigActions[SIG_NUM_SIGNALS];     /* Array of the different types
  275.                        of actions for signals. */
  276.     int    sigMasks[SIG_NUM_SIGNALS];     /* Array of signal hold masks for 
  277.                        signal handlers. */
  278.     int    sigCodes[SIG_NUM_SIGNALS];     /* Array of signal handlers for 
  279.                        signals. */
  280.  
  281. } Proc_DebugState;
  282.  
  283. /*
  284.  * Structure that represents one environment variable.
  285.  */
  286.  
  287. typedef struct {
  288.     char *name;        /* Variable name. */
  289.     char *value;    /* Value for variable. */
  290. } Proc_EnvironVar;
  291.  
  292. /*
  293.  * Process information. Add new fields to the end of this structure!
  294.  */
  295. typedef struct  {
  296.     int        processor;    /* Processor number the process is running on
  297.                  * or wants to run on if the processor is
  298.                  * available.  */
  299.  
  300.     Proc_State    state;        /* Describes a process's current running state.
  301.                  * >>> See Proc_State definitions above. */ 
  302.  
  303.     int        genFlags;    /* Flags to describe a processes overall state.
  304.                  * >>> See definitions below */ 
  305.  
  306.     /*
  307.      *-----------------------------------------------------------------
  308.      *
  309.      *   Various Process Identifiers.
  310.      *    
  311.      *    Note that the user and effectiveUser ID are kept here because
  312.      *    they are used for permission checking in various places.  There
  313.      *    is also a list of group IDs which is kept in the filesystem state.
  314.      *
  315.      *-----------------------------------------------------------------
  316.      */
  317.  
  318.     Proc_PID    processID;        /* Actual process ID of this
  319.                      * process (for migrated processes
  320.                      * this is different than the PID
  321.                      * that the user sees). */
  322.     Proc_PID    parentID;        /* The process ID of the parent 
  323.                      * of this process. */
  324.     int        familyID;        /* The id of the process family that 
  325.                      * this process belongs to. */
  326.     int        userID;            /* The user id is used to check access
  327.                      * rights to files and check ability
  328.                      * to signal other processes. */
  329.     int        effectiveUserID;    /* The effective user id is used
  330.                      * for setuid access. */
  331.  
  332.     /*
  333.      *-----------------------------------------------------------------
  334.      *
  335.      *    Synchronization fields.
  336.      *
  337.      * Synchronization state includes an event the process is waiting on.
  338.      *
  339.      *-----------------------------------------------------------------
  340.      */
  341.  
  342.     int         event;         /* Event # the process is waiting for. */
  343.  
  344.     /*
  345.      *-----------------------------------------------------------------
  346.      *
  347.      *    Scheduling fields.
  348.      *
  349.      *-----------------------------------------------------------------
  350.      */
  351.  
  352.  
  353.     int      billingRate;    /* Modifies the scheduler's calculation of
  354.                  * the processes priority.  */
  355.     unsigned int recentUsage;    /* Amount of CPU time used recently */
  356.     unsigned int weightedUsage;    /* Smoothed avg. of CPU usage, weighted by
  357.                  * billing rate. */
  358.     unsigned int unweightedUsage; /* Smoothed avg. of CPU usage, not weighted by
  359.                    * billing rate. */
  360.  
  361.     /*
  362.      *-----------------------------------------------------------------
  363.      *
  364.      *    Accounting and Resource Usage fields.
  365.      *
  366.      *-----------------------------------------------------------------
  367.      */
  368.  
  369.     Time kernelCpuUsage;    /* How much time has been spent in kernel mode*/
  370.     Time userCpuUsage;        /* How much time has been spent in user mode. */
  371.  
  372.     Time childKernelCpuUsage;    /* Sum of time spent in kernel mode for 
  373.                       * all terminated children. */
  374.     Time childUserCpuUsage;    /* Sum of time spent in user mode for
  375.                       * all terminated children. */
  376.     int     numQuantumEnds;        /* number of times the process was 
  377.                       * context switched due to a quantum 
  378.                      * end. */
  379.     int        numWaitEvents;        /* number of times the process was
  380.                      * context switched due to its waiting 
  381.                      * for an event. */
  382.     unsigned int schedQuantumTicks;    /* Number of clock ticks until this 
  383.                      * process is due to be switched out. */
  384.  
  385.     /*
  386.      *-----------------------------------------------------------------
  387.      *
  388.      *   Virtual Memory fields.
  389.      *
  390.      *-----------------------------------------------------------------
  391.      */
  392.     Vm_SegmentID        vmSegments[VM_NUM_SEGMENTS];
  393.  
  394.  
  395.     /*
  396.      *-----------------------------------------------------------------
  397.      *
  398.      *    Signals
  399.      *
  400.      *-----------------------------------------------------------------
  401.      */
  402.  
  403.     int        sigHoldMask;        /* Mask of signals to be held. */
  404.     int        sigPendingMask;        /* Mask of pending signals. */
  405.                         /* Array of the different types
  406.                        of actions for signals. */
  407.     int        sigActions[SIG_NUM_SIGNALS];
  408.                         /* Array of signal hold masks for 
  409.                        signal handlers. */
  410.     /*
  411.      *---------------------------------------------------------------------
  412.      *
  413.      * Data for process migration.
  414.      *
  415.      *---------------------------------------------------------------------
  416.      */
  417.     int        peerHostID;         /* If on home node, ID of remote node.
  418.                       * If on remote node, ID of home node.
  419.                       * If not migrated, undefined. */
  420.     Proc_PID    peerProcessID;         /* If on remote note, process ID on
  421.                       * home node, and vice-versa. */
  422. } Proc_PCBInfo;
  423.  
  424. /*
  425.  * Define the maximum length of the name and value of each enviroment
  426.  * variable and the maximum size of the environment.
  427.  */
  428.  
  429. #define    PROC_MAX_ENVIRON_NAME_LENGTH    512
  430. #define    PROC_MAX_ENVIRON_VALUE_LENGTH    512
  431. #define    PROC_MAX_ENVIRON_SIZE        100
  432.  
  433. /*
  434.  * Define the maximum size of the first line of an interpreter file.
  435.  */
  436.  
  437. #define PROC_MAX_INTERPRET_SIZE        80
  438.  
  439. /*
  440.  * Definitions for the Proc_G/SetIntervalTimer system calls.
  441.  *
  442.  * Currently, only 1 type of timer is defined:
  443.  *  PROC_TIMER_REAL -  time between intervals is real (a.k.a wall-clock) time.
  444.  *
  445.  * The values and the structure have the same values and layout as their 
  446.  * 4.3BSD equivalents.
  447.  */
  448.  
  449. #define PROC_TIMER_REAL        0
  450. /*
  451.  * not used yet.
  452. #define PROC_TIMER_VIRTUAL    1
  453. #define PROC_TIMER_PROFILE    2
  454. */
  455.  
  456. #define PROC_MAX_TIMER        PROC_TIMER_REAL
  457.  
  458. typedef struct {
  459.     Time    interval;    /* Amount of time between timer expirations. */
  460.     Time    curValue;    /* Amount of time till the next expiration. */
  461. } Proc_TimerInterval;
  462.  
  463. /* 
  464.  * Size of the buffer containing arguments, to be passed back to users.  
  465.  */
  466.  
  467. #define PROC_PCB_ARG_LENGTH 256
  468.  
  469. /*
  470.  * The following structure is used to transfer fixed-length argument strings
  471.  * from the kernel back to user space.  A typedef simplifies later
  472.  * declarations (and may be the only way to do it?), since 
  473.  *    char *argPtr[PROC_PCB_ARG_LENGTH]
  474.  * would be an array of pointers to strings rather than an array of strings.
  475.  */
  476.  
  477. typedef struct {
  478.     char argString[PROC_PCB_ARG_LENGTH];
  479. } Proc_PCBArgString;
  480.  
  481.  
  482. /*
  483.  * Define the state of this machine w.r.t accepting migrated processes.
  484.  * A machine must always be willing to accept its own processes if they
  485.  * are migrated home.  Other than that, a host may allow migrations onto
  486.  * it under various sets of criteria, and may allow migrations away from
  487.  * it under similar sets of criteria.
  488.  *
  489.  *    PROC_MIG_IMPORT_NEVER        - never allow migrations to this host.
  490.  *    PROC_MIG_IMPORT_ROOT         - allow migrations to this host only
  491.  *                      by root.
  492.  *    PROC_MIG_IMPORT_ALL          - allow migrations by anyone.
  493.  *    PROC_MIG_IMPORT_ANYINPUT     - don't check keyboard input when
  494.  *                      determining availability.
  495.  *    PROC_MIG_IMPORT_ANYLOAD      - don't check load average when
  496.  *                      determining availability.
  497.  *    PROC_MIG_IMPORT_ALWAYS      - don't check either.
  498.  *    PROC_MIG_EXPORT_NEVER        - never export migrations from this
  499.  *                       host.
  500.  *    PROC_MIG_EXPORT_ROOT            - allow only root to export.
  501.  *    PROC_MIG_EXPORT_ALL            - allow anyone to export.
  502.  *
  503.  * For example, a reasonable default for a file server might be to import
  504.  * and export only for root; for a user's machine, it might be to allow
  505.  * anyone to migrate; and for a compute server, it might never export
  506.  * and import always regardless of load average or keyboard input.  (The
  507.  * load average would not have to be exceptionally low to determine
  508.  * availability; the host still would only be selected if the load average
  509.  * were low enough to gain something by migrating to it.)
  510.  */
  511.  
  512. #define PROC_MIG_IMPORT_NEVER              0
  513. #define PROC_MIG_IMPORT_ROOT        0x00000001
  514. #define PROC_MIG_IMPORT_ALL         0x00000003
  515. #define PROC_MIG_IMPORT_ANYINPUT    0x00000010
  516. #define PROC_MIG_IMPORT_ANYLOAD        0x00000020
  517. #define PROC_MIG_IMPORT_ALWAYS  \
  518.             (PROC_MIG_IMPORT_ANYINPUT | PROC_MIG_IMPORT_ANYLOAD)
  519. #define PROC_MIG_EXPORT_NEVER             0
  520. #define PROC_MIG_EXPORT_ROOT        0x00010000
  521. #define PROC_MIG_EXPORT_ALL        0x00030000
  522.  
  523. #define PROC_MIG_ALLOW_DEFAULT (PROC_MIG_IMPORT_ALL | PROC_MIG_EXPORT_ALL)
  524.  
  525. /*
  526.  * Library call declarations.
  527.  */
  528.  
  529. extern ReturnStatus Proc_SetExitHandler();
  530. extern void        Proc_Exit();
  531.  
  532. /*
  533.  * System call declarations.
  534.  */
  535.  
  536. extern ReturnStatus Proc_Fork();
  537. extern void        Proc_RawExit();
  538. extern ReturnStatus Proc_Detach();
  539. extern ReturnStatus Proc_Wait();
  540. extern ReturnStatus Proc_RawWait();
  541. extern ReturnStatus Proc_Exec();
  542. extern ReturnStatus Proc_ExecEnv();
  543.  
  544. extern ReturnStatus Proc_GetIDs();
  545. extern ReturnStatus Proc_SetIDs();
  546. extern ReturnStatus Proc_GetGroupIDs();
  547. extern ReturnStatus Proc_SetGroupIDs();
  548. extern ReturnStatus Proc_GetFamilyID();
  549. extern ReturnStatus Proc_SetFamilyID();
  550.  
  551. extern ReturnStatus Proc_GetPCBInfo();
  552. extern ReturnStatus Proc_GetResUsage();
  553. extern ReturnStatus Proc_GetPriority();
  554. extern ReturnStatus Proc_SetPriority();
  555.  
  556. extern ReturnStatus Proc_Debug();
  557. extern ReturnStatus Proc_Profile();
  558.  
  559. extern ReturnStatus Proc_SetIntervalTimer();
  560. extern ReturnStatus Proc_GetIntervalTimer();
  561.  
  562. extern ReturnStatus Proc_SetEnviron();
  563. extern ReturnStatus Proc_UnsetEnviron();
  564. extern ReturnStatus Proc_GetEnvironVar();
  565. extern ReturnStatus Proc_GetEnvironRange();
  566. extern ReturnStatus Proc_InstallEnviron();
  567. extern ReturnStatus Proc_CopyEnviron();
  568.  
  569. extern ReturnStatus Proc_Migrate();
  570.  
  571. #endif /* _PROCUSER */
  572.